package com.ccl.keyassistant.view;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.ccl.keyassistant.R;


/*
 *项目名     keyassistant
 *包名       com.ccl.keyassistant.view
 *文件名     CustomDialog
 *创建者     ccl
 *创建时间   2019-03-08 14:52
 *注解       自定义Dialog
 */

public class CustomDialog extends Dialog {


    public CustomDialog(Context context) {
        //默认样式
        this(context, R.layout.custom_dialog_default, R.style.CustomDialogStyleDef);
    }

    public CustomDialog(Context context, View view) {
        //默认样式
        super(context,  R.style.CustomDialogStyleDef);
        setContentView(view);
    }




    public CustomDialog(Context context, int layout) {
        //默认样式
        this(context, layout, R.style.CustomDialogStyleDef);
    }

    public CustomDialog(@NonNull Context context, int layout, int themeResId, int anim) {
        this(context, layout, themeResId, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT
                , Gravity.CENTER, anim);
    }

    public CustomDialog(Context context, int layout, int themeResId) {

        this(context, layout, themeResId, R.style.CustomDialogAnimDef);
    }


    public CustomDialog(Context context, int layout, int themeResId, int height, int width, int gravity, int anim) {
        super(context, themeResId);
        //设置显示布局
        //注意，当布局中的View小写时（view）会报空指针异常
        setContentView(layout);
        //设置宽高
        Window window = getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.width = width;
        attributes.height = height;
        attributes.gravity = gravity;
        window.setAttributes(attributes);

        window.setWindowAnimations(anim);
    }


}
